import Vue from 'vue'
import * as Util from '../components/Util'

let DiscountsService = {
  install (Vue, options) {
    // 给vue增添对话框显示方法
    Vue.DiscountsService = Vue.prototype.$DiscountsService = DiscountsService
  },
  addDiscounts (model, row) {
    let data = {
      f_user_id: row.f_user_id,
      f_discounts_style: model.f_discounts_style[0].f_discounts_type,
      f_discount_water: model.f_discounts_style[0].f_discount_water,
      f_discount_proport: model.f_discounts_style[0].f_discount_proport,
      f_waterproperties: model.f_waterproperties,
      f_start_date: model.f_start_date,
      f_finish_date: model.f_finish_date,
      f_note: model.f_note,
      f_base_id: model.f_base_price[0].f_price_id,
      f_audit: '审核通过',
      f_state: '有效',
      f_operator: Util.f.name,
      f_filiale: Util.f.f_fengongsi,
      f_outlets: Util.f.f_parentname
    }
    if (data.f_discount_water <= 0) {
      data.f_discounts_type = '按比例'
    } else if (data.f_discount_water > 0) {
      data.f_discounts_type = '按水量'
    }
    return Vue.resetpost('rs/entity/t_discountsprice', data, {resolveMsg: '添加优惠成功', rejectMsg: '添加优惠失败'})
  }
}

export default DiscountsService
